import random
import sys
import subprocess


def dump_object(link_file):
    out = subprocess.check_output(['arm-none-eabi-objdump', '-t', link_file])
    lines = out.decode().split('\n')

    ret = {}

    for line in lines:
        data = line.split()
        if len(data) == 6:
            ret[data[5]] = int(data[0], 16)
    return ret


def fill_unuse_value(in_file, arg: str, symbol: str):
    symbols = dump_object(arg)

    with open(in_file, 'rb+') as file:
        start = symbols[symbol] - 0x8000000 + 0x500
        print("填充字节： %s, %x" % (in_file, start))
        file.seek(start)
        for x in range(start, 0x2000000 - 4, 4):
            file.write(random.randint(0, 0xffffffff).to_bytes(4, 'little'))


fill_unuse_value(sys.argv[1], sys.argv[2], sys.argv[3])
